<?php
/**
 * Author: Administrator
 * Date: 2022/7/23 22:45
 */

namespace DesignPatterns\Behavioral\Iterator;

class BookList implements \Countable
{
    protected array $books;

    public function getBook($idx) {
        if (isset($this->books[$idx])) {
            return $this->books[$idx];
        }
        throw new \OutOfRangeException('out of range!');
    }

    public function addBook(Book $book) {
        $this->books[] = $book;
    }

    public function count(): int
    {
        return \count($this->books);
    }
}